Validating XML in dxl

I have a dxl script that runs and exports some things into xml. At runtime, I would like to validate the xml to make sure that it is correct. To do this I was using the undocumented APi parseXMLBuffer_(Buffer)

This is the function that I have came up with that works when the XML is valid, but when it is invalid, it blows up. Any thoughts on how to catch suppress any error that comes up in the parseXMLBuffer_()? I don't use the DOM_Document_ for anything, I'm just using it to validate the XML.

bool isXMLValid(Buffer bufOutput)
{
noError()
DOM_Document_ temp = parseXMLBuffer_ (bufOutput)
string ErrMess = lastError()
if (!null ErrMess)
{
return false
}
else
{
return true
}
}
gandr - Mon Aug 15 11:43:52 EDT 2011

Re: Validating XML in dxl
llandale - Mon Aug 15 17:54:59 EDT 2011

Not familiar with XML or any of this. But if you want to see if some DXL works you can package it up and send it to "eval_" and check for errors. Someone will surely correct this post and also tell us how to send a Buffer to eval_ (send its address), but the code would look something like this.

bool isXMLValid(Buffer bufOutput)
{
    string XML = tempStringOf(bufOutput)
        string DXL ="DOM_Document_ temp = parseXMLBuffer_ (\"" XML "\")
        return_(\"OK\")
        "  // end definition of string DXL
 
        string Results = eval_(DXL)
        return(Results == "OK")
}

 

  • Louie

 

Re: Validating XML in dxl
SystemAdmin - Mon Aug 15 18:08:34 EDT 2011

llandale - Mon Aug 15 17:54:59 EDT 2011

Not familiar with XML or any of this. But if you want to see if some DXL works you can package it up and send it to "eval_" and check for errors. Someone will surely correct this post and also tell us how to send a Buffer to eval_ (send its address), but the code would look something like this.

bool isXMLValid(Buffer bufOutput)
{
    string XML = tempStringOf(bufOutput)
        string DXL ="DOM_Document_ temp = parseXMLBuffer_ (\"" XML "\")
        return_(\"OK\")
        "  // end definition of string DXL
 
        string Results = eval_(DXL)
        return(Results == "OK")
}

 

  • Louie

 

What is the difference between eval_ and checkDXL?
-Adam

Re: Validating XML in dxl
llandale - Mon Aug 15 18:51:54 EDT 2011

SystemAdmin - Mon Aug 15 18:08:34 EDT 2011
What is the difference between eval_ and checkDXL?
-Adam

checkDXL just interprets but does not run it; much as if the 1st line of the DXL was "halt". eval_ runs it in its own DXL context; which some of the clever folks here can manipulate rather deftly.

My trigger deploy code uses checkDXL and won't deploy unless it at least interprets.

  • Louie

Re: Validating XML in dxl
gandr - Tue Aug 16 11:29:29 EDT 2011

llandale - Mon Aug 15 18:51:54 EDT 2011
checkDXL just interprets but does not run it; much as if the 1st line of the DXL was "halt". eval_ runs it in its own DXL context; which some of the clever folks here can manipulate rather deftly.

My trigger deploy code uses checkDXL and won't deploy unless it at least interprets.

  • Louie

Thanks for the reply Louie. I tried this, but the issue is, the xml is littered with double quotes. Causing all sorts of concatenation errors when it runs. Any thoughts on how to get around this?

Re: Validating XML in dxl
llandale - Tue Aug 16 15:50:08 EDT 2011

gandr - Tue Aug 16 11:29:29 EDT 2011
Thanks for the reply Louie. I tried this, but the issue is, the xml is littered with double quotes. Causing all sorts of concatenation errors when it runs. Any thoughts on how to get around this?

Eack. You would need to escape all the double quotes and all the back-slashes with a backs-slash.
e.g. turn: abc\d"0o\"dd into
abc\\d\"0o\\\"dd

Too lazy to search previous threads for that.

Not sure this is such a good solution for you any more.

  • Louie

Re: Validating XML in dxl
Mathias Mamsch - Thu Aug 18 05:30:03 EDT 2011

gandr - Tue Aug 16 11:29:29 EDT 2011
Thanks for the reply Louie. I tried this, but the issue is, the xml is littered with double quotes. Causing all sorts of concatenation errors when it runs. Any thoughts on how to get around this?

The easy workaround is: Don't embed the XML directly, just write it to a file and read the file from the eval context, or pass the buffer directly to the eval context:

bool isXMLValid(Buffer bufOutput)
{
    // pass Buffer directly in eval context
        string DXL = "
Buffer result = addr_ " ((addr_ bufOutput) int) "
DOM_Document_ temp = parseXMLBuffer_ result
return_(null temp ? \"NULL\" : \"OK\")
"  // end definition of string DXL
 
        string Results = eval_(DXL); 
        return(Results == "OK")
}
 
Buffer x = create(); 
 
x = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROOT/>"
print "VALID:" (isXMLValid x) "\n"
 
x = "Hallo"
print "VALID:" (isXMLValid x) "\n"

 


Hope this helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Validating XML in dxl
gandr2 - Thu Aug 18 09:34:24 EDT 2011

Mathias Mamsch - Thu Aug 18 05:30:03 EDT 2011

The easy workaround is: Don't embed the XML directly, just write it to a file and read the file from the eval context, or pass the buffer directly to the eval context:

bool isXMLValid(Buffer bufOutput)
{
    // pass Buffer directly in eval context
        string DXL = "
Buffer result = addr_ " ((addr_ bufOutput) int) "
DOM_Document_ temp = parseXMLBuffer_ result
return_(null temp ? \"NULL\" : \"OK\")
"  // end definition of string DXL
 
        string Results = eval_(DXL); 
        return(Results == "OK")
}
 
Buffer x = create(); 
 
x = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ROOT/>"
print "VALID:" (isXMLValid x) "\n"
 
x = "Hallo"
print "VALID:" (isXMLValid x) "\n"

 


Hope this helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Thanks Mathias, that works better, but I still get an unspecified error when I throw in a chunk of invalid xml. However, at least it is not hanging up DOORs. I'l stick with this solution as it gives me enough information to figure out which xml buffer is bad.

For completeness, Here is the error that I am getting:
DXL: <Line:3> An unexpected error has occurred: doors.exe caused an EXCEPTION_ACCESS_VIOLATION in module xml4c-depdom_5_7.dll at 001B:1201CCF8, xml4c_5_7::RefCountedImpl::removeRef()+0008 byte(s)

-R-F- DXL: <Line:3> internal error, please submit a bug report
-R-E- DXL: <Line:3> An unexpected error has occurred: Unspecified Failure

Re: Validating XML in dxl
Mathias Mamsch - Thu Aug 18 11:11:48 EDT 2011

gandr2 - Thu Aug 18 09:34:24 EDT 2011
Thanks Mathias, that works better, but I still get an unspecified error when I throw in a chunk of invalid xml. However, at least it is not hanging up DOORs. I'l stick with this solution as it gives me enough information to figure out which xml buffer is bad.

For completeness, Here is the error that I am getting:
DXL: <Line:3> An unexpected error has occurred: doors.exe caused an EXCEPTION_ACCESS_VIOLATION in module xml4c-depdom_5_7.dll at 001B:1201CCF8, xml4c_5_7::RefCountedImpl::removeRef()+0008 byte(s)

-R-F- DXL: <Line:3> internal error, please submit a bug report
-R-E- DXL: <Line:3> An unexpected error has occurred: Unspecified Failure

Try doing the XML parsing of the same content outside of the eval_ context. If you still get the error you found a bug. If not ... hmmmm ... There is a small chance that the error comes from passing the buffer directly to the eval_ context (although I am not sure, why this should happen). If speed and resource usage (large string table entries!) is not your concern, you then should switch to using the ToBase64 FromBase64 functions to convert the XML into text that needs not to be escaped and embed it in the DXL and convert it back. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS